<?php
// +----------------------------------------------------------------------
// | snake
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai <1902822973@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\model;

use think\Db;
use think\Model;

class SystemRole extends Model
{
    public static $tableName = 'vote_system_role';

    public function getAllRoles(){
        return Db::table(static::$tableName)->field('id,rolename')->where('is_del=0')->select();
    }

    public function getRolesAll($where, $offset, $limit){
        return Db::table(static::$tableName)->field('id,rolename,c_time')->where($where)->limit($offset.','.$limit)->select();
    }

    public function getCount($where){
        return Db::table(static::$tableName)->where($where)->count();
    }

    public function add($data){
        return $this->insert($data) == 1;
    }

    public function edit($data){
        return Db::table(static::$tableName)->update($data) == 1;
    }

    public function del($managerId){
        return Db::table(static::$tableName)->update(['id'=>$managerId, 'is_del'=>time()]) == 1;
    }

    //获取角色的权限节点
    public function getRuleById($id)
    {
        return Db::table(static::$tableName)->where('id', $id)->value('rule', '');
    }

    public function editAccess($data){
        return Db::table(static::$tableName)->update($data) == 1;
    }

}
